<?php
/**
 * Created by PhpStorm.
 * User: tengwei
 * Date: 2018/11/22
 * Time: 9:56 AM
 */

namespace common\sources\write\businesscash;

use Yii;
use common\models\craftsman\BusinessCash;

class BusinessCashAccess implements IBusinessCashAccess {
	// 状态改变
	public function modifyCashRecord($data) {
		$sql = 'UPDATE ' . BusinessCash::tableName() . ' SET reason = :reason,cash_status = :cash_status,update_time=:update_time WHERE id = :id ';
		return Yii::$app->db->createCommand($sql)
			->bindValues([
				':reason'      => $data['reason'],
				':cash_status' => $data['status'],
				':update_time' => time(),
				':id'          => $data['id']
			])->execute();
	}

	// 修改备注
	public function editCashRecordRemark($data) {
		$sql = 'UPDATE ' . BusinessCash::tableName() . ' SET remark=:remark WHERE id = :id ';
		return Yii::$app->db->createCommand($sql)
			->bindValues([
				':remark' => $data['remark'],
				':id'     => $data['id']
			])->execute();
	}


	/**
	 * editData 审核操作
	 *
	 * @param $data
	 *
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/10
	 * @return int
	 * @throws \yii\db\Exception
	 */
	public function auditData($data) {
		$sql = 'UPDATE ' . BusinessCash::tableName() . ' SET reason = :reason,cash_status = :cash_status,update_time=:update_time,auditor_time=:auditor_time ,auditor_user=:auditor_user WHERE id = :id ';
		return Yii::$app->db->createCommand($sql)
			->bindValues([
				':reason'       => $data['reason'],
				':cash_status'  => $data['status'],
				':update_time'  => time(),
				':auditor_time' => time(),
				':auditor_user' => $data['operator'],
				':id'           => $data['id']
			])->execute();
	}

	/**
	 * endData 提现完成
	 *
	 * @param $data
	 *
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/10
	 * @return int
	 * @throws \yii\db\Exception
	 */
	public function endData($data) {
		$sql = 'UPDATE ' . BusinessCash::tableName() . ' SET reason = :reason,cash_status = :cash_status,update_time=:update_time,end_time=:end_time,end_user=:end_user ,kq_serial_number=:kq_serial_number WHERE id = :id ';
		$re =  Yii::$app->db->createCommand($sql)
			->bindValues([
				':reason'           => $data['reason'],
				':cash_status'      => $data['status'],
				':update_time'      => time(),
				':end_time'         => time(),
				':end_user'         => $data['operator'],
				':kq_serial_number' => isset($data['kq_serial_number']) ? $data['kq_serial_number'] : null,
				':id'               => $data['id']
			])->execute();
		return $re;
	}
}